package com.sykj.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sykj.entity.Classes;
import com.sykj.entity.Student;
import com.sykj.entity.StudentCustemer;
import com.sykj.service.StudentService;

@Controller
@RequestMapping("/student")
public class StudentController {

	@Autowired
	private StudentService studentService;
	
	@RequestMapping("/queryAll")
	@ResponseBody
	public List<StudentCustemer> queryAll(@RequestBody Student student){
		return studentService.queryAll(student);
	}
	
	@RequestMapping("/queryClass")
	@ResponseBody
	public List<Classes> queryClass(){
		return studentService.queryClass();
	}
	
	@RequestMapping("/deleteStudent/{stuno}")
	@ResponseBody
	public Map<String, Object> deleteStudent(@PathVariable("stuno") Integer stuno){
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			studentService.deleteStudent(stuno);
			map.put("state", true);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("state", false);
		}
		return map;
	}
	
	@RequestMapping("/insertStudent")
	@ResponseBody
	public Map<String, Object> insertStudent(@RequestBody Student student){
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			studentService.insertStudent(student);
			map.put("state", true);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("state", false);
		}
		return map;
	}
	
	@RequestMapping("/queryById/{stuno}")
	@ResponseBody
	public Student queryById(@PathVariable("stuno") Integer stuno){
		return studentService.queryById(stuno);
	}
	
	@RequestMapping("/updateStudent")
	@ResponseBody
	public Map<String, Object> updateStudent(@RequestBody Student student){
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			studentService.updateStudent(student);
			map.put("state", true);
		} catch (Exception e) {
			e.printStackTrace();
			map.put("state", false);
		}
		return map;
	}
	
}
